package org.codeart.observer.hosue2;

import org.codeart.observer.dto.LotteryResult;
import org.codeart.observer.hosue2.EventManager.EventType;

/**
 * 开奖服务接口
 */
public abstract class LotteryService {

    private final EventManager eventManager;

    public LotteryService() {
        // 设置事件的类型
        eventManager = new EventManager(EventType.MQ, EventType.Message);
        
        // 订阅
        eventManager.subscribe(EventType.Message, new MessageEventListener());
        eventManager.subscribe(EventType.MQ, new MqEventListener());
    }
    
    public LotteryResult lotteryAndCall(String uid) {
        LotteryResult result = lottery(uid);
        // 发送通知
        eventManager.inform(EventType.Message, result);
        eventManager.inform(EventType.MQ, result);
        return result;
    }
    
    public abstract LotteryResult lottery(String uid);
}
